package com.xiaopeng.system.common.config;


import com.common.operationLog.controller.OperationLogController;
import com.common.operationLog.pojo.bo.OperationLogContext;
import com.common.operationLog.pojo.bo.OperationLogUserInfoContext;
import com.common.operationLog.service.IOperationLogService;
import com.common.operationLog.service.impl.OperationLogServiceImpl;
import com.xiaopeng.system.common.enums.OperationLogTypeEnum;
import com.xiaopeng.system.common.holder.UserHolder;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * 操作日志配置
 */
@Configuration
public class OperationLogConfig {

    @Bean
    public OperationLogContext operationLogContext() {
        OperationLogContext operationLogContext = new OperationLogContext();
        // 设置枚举列表-用于下拉框
        operationLogContext.setOperationLogModuleTypeList(List.of(OperationLogTypeEnum.values()));
        // 设置用户信息上下文 若保存日志时未设置操作人信息，将从用户信息上下文中获取
        operationLogContext.setOperationLogUserInfoContextSupplier(() -> {
            OperationLogUserInfoContext operationLogUserInfoContext = new OperationLogUserInfoContext();
            operationLogUserInfoContext.setOperationBy(UserHolder.getUserId());
            operationLogUserInfoContext.setOperationByName(UserHolder.getUserName());
            return operationLogUserInfoContext;
        });
        return operationLogContext;
    }

}
